package com.pzhu.dormitory.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pzhu.dormitory.dao.BuildingDao;
import com.pzhu.dormitory.entity.BuildingEntity;
import com.pzhu.dormitory.entity.MenuEntity;
import com.pzhu.dormitory.service.BuildingService;
import com.pzhu.dormitory.utils.PageUtils;
import com.pzhu.dormitory.utils.Query;
import com.pzhu.dormitory.vo.BuildingVo;
import com.pzhu.dormitory.vo.StudentVo;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("buildingService")
@AllArgsConstructor
public class BuildingServiceImpl extends ServiceImpl<BuildingDao, BuildingEntity> implements BuildingService {

    private final BuildingDao buildingDao;
    @Override
    public PageUtils<BuildingEntity> queryPage(Map<String, Object> params) {
        QueryWrapper<BuildingEntity> queryWrapper = new QueryWrapper<>();
        String name = (String) params.get("name");
        if (StringUtils.isNotBlank(name)) {
            queryWrapper.lambda().like(BuildingEntity::getName, "%" + name + "%");
        }
        IPage<BuildingEntity> page = this.page(
                new Query<BuildingEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils<>(page);
    }

    @Override
    public PageUtils<BuildingVo> queryPageBuildingVo(Map<String, Object> params) {
        Page<BuildingVo> page = new Query<BuildingVo>().getPage(params);
        // 查询基本数据
        Page<BuildingVo> buildingVoPage = buildingDao.queryPageVo(page, params);
        return new PageUtils<>(buildingVoPage);
    }

}
